//服务器接口路径
var host_name = window.location.hostname =='localhost'?'119.23.232.192':window.location.hostname;
var serverUrl={
    // base:'http://119.23.232.192:8081/',
    // base:'http://10.87.140.204:8081/',
    base:'http://'+host_name+':8081/',
    login:'Organization/users/login',
    count:'Grid/Count/',
    organize:'Organization/organize/',
    department:'Organization/department/',
    importbatch:'Organization/Importsave/',
    informationType:'Organization/information/',
    user:'Organization/users/',
    post:'Organization/post/',
    quantification:'Quantification/Quantification/',
    grid:'Organization/grid/',
    device:'Device/device/',
    taskTrainStation:'Organization/station/',
    taskTrain:'Organization/train/',
    emergency:'Emergency/Emergency/',
    mapUrl:'',
    workTask:'Worktask/Worktask/'
}
//select2 本地数据
var select2Datas = {
    trainCycle:[
        {id:'1',text:'每天'},
        {id:'2',text:'隔日'},
        {id:'3',text:'每周'},
        {id:'4',text:'开一停二'},
        {id:'5',text:'开二停一'}
    ],
    task:[
        {id:'1',text:'作业流程1'},
        {id:'2',text:'作业流程2'},
        {id:'3',text:'作业流程3'},
        {id:'4',text:'作业流程4'}
    ],
    gridTips:[
        {id:'1',text:'站台区'},
        {id:'2',text:'候车区'},
        {id:'3',text:'厕所'},
        {id:'4',text:'售票厅'}
    ],
    tempGrid:[
        {id:'1',text:'候车室1'},
        {id:'2',text:'候车室2'},
        {id:'3',text:'候车室3'},
        {id:'4',text:'候车室4'},
        {id:'5',text:'候车室5'},
        {id:'6',text:'候车室6'}
    ],
    quantiRate:[
        {id:'2',text:'2小时巡视'},
        {id:'6',text:'6小时巡视'},
        {id:'8',text:'8小时巡视'},
        {id:'12',text:'12小时巡视'}
    ],
    day:[
        {id:'0',text:'0天'},
        {id:'1',text:'1天'},
        {id:'2',text:'2天'},
        {id:'3',text:'3天'},
        {id:'4',text:'4天'},
        {id:'5',text:'5天'},
        {id:'6',text:'6天'},
        {id:'7',text:'7天'},
        {id:'8',text:'8天'},
        {id:'9',text:'9天'},
        {id:'10',text:'10天'},
        {id:'11',text:'11天'},
        {id:'12',text:'12天'},
        {id:'13',text:'13天'},
        {id:'14',text:'14天'},
        {id:'15',text:'15天'},
        {id:'16',text:'16天'},
        {id:'17',text:'17天'},
        {id:'18',text:'18天'},
        {id:'19',text:'19天'},
        {id:'20',text:'20天'},
        {id:'21',text:'21天'},
        {id:'22',text:'22天'},
        {id:'23',text:'23天'},
        {id:'24',text:'24天'},
        {id:'25',text:'25天'},
        {id:'26',text:'26天'},
        {id:'27',text:'27天'},
        {id:'28',text:'28天'},
        {id:'29',text:'29天'},
        {id:'30',text:'30天'}
    ],
    hour:[
        {id:'0',text:'0小时'},
        {id:'1',text:'1小时'},
        {id:'2',text:'2小时'},
        {id:'3',text:'3小时'},
        {id:'4',text:'4小时'},
        {id:'5',text:'5小时'},
        {id:'6',text:'6小时'},
        {id:'7',text:'7小时'},
        {id:'8',text:'8小时'},
        {id:'9',text:'9小时'},
        {id:'10',text:'10小时'},
        {id:'11',text:'11小时'},
        {id:'12',text:'12小时'},
        {id:'13',text:'13小时'},
        {id:'14',text:'14小时'},
        {id:'15',text:'15小时'},
        {id:'16',text:'16小时'},
        {id:'17',text:'17小时'},
        {id:'18',text:'18小时'},
        {id:'19',text:'19小时'},
        {id:'20',text:'20小时'},
        {id:'21',text:'21小时'},
        {id:'22',text:'22小时'},
        {id:'23',text:'23小时'},
        {id:'24',text:'24小时'}
    ],
    xjcycle:[
        {id:'1',text:'1天1次'},
        {id:'2',text:'7天1次'},
        {id:'3',text:'30天1次'}
    ]
}
//vue 静态store
var vueStore={
    state:{
        serverUrl:serverUrl,
        select2Datas:select2Datas
    },
    setSelId:function(id){
        this.state.selId = id
    }
}
//storage 操作
var storageControl={
    storagable:function(){
        if (typeof(Storage) !== "undefined") {
            return true
         }else{
            console.log("抱歉！您的浏览器不支持 Web Storage ...");
            return false
         }
    },
    islogined:function(){
        if(this.storagable()){
            var _uid = localStorage.getItem('user_id') || ''
            if(_uid == ''){
                window.location.href='./login.html';
            }

        }
    },
    clear:function(){
        if(this.storagable()){
            //var _uid = localStorage.getItem('user_id') || ''
            localStorage.clear();
            sessionStorage.clear();
        }
    },
    setStorage:function(data){
        if(this.storagable()){
            for(var i in data){
                localStorage.setItem(i, data[i]);
            }
        }
    },
    isloginedS:function(){
        if(this.storagable()){
            var _uid = sessionStorage.getItem('user_id') || ''
            var _pathName = window.location.pathname
            //console.log(/login/.test(_pathName))
            if(_uid == '' &&  !/login/.test(_pathName)){
                window.location.href='./login.html';
            }
        }
    },
    setStorageS:function(data){
        if(this.storagable()){
            for(var i in data){
                sessionStorage.setItem(i, data[i]);
            }
        }
    }
}
//判断浏览器
var browser={
    versions:function(){
        var u = navigator.userAgent, app = navigator.appVersion;
        return {         //移动终端浏览器版本信息
             trident: u.indexOf('Trident') > -1, //IE内核
            presto: u.indexOf('Presto') > -1, //opera内核
            webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
            gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
            mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
            ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
            android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或uc浏览器
            iPhone: u.indexOf('iPhone') > -1 , //是否为iPhone或者QQHD浏览器
            iPad: u.indexOf('iPad') > -1, //是否iPad
            webApp: u.indexOf('Safari') == -1, //是否web应该程序，没有头部与底部
            _IE:function(){
                var v = 3, div = document.createElement('div'), all = div.getElementsByTagName('i');
                while (
                    div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->',
                    all[0]
                );
                return v > 4 ? v : false ;
              }
        };
    }(),
    language:(navigator.browserLanguage || navigator.language).toLowerCase()
  }
//cookie 操作
var cookieControl={
    setCookie:function(name,value){
        //写cookies
        var Days = 30; 
        var exp = new Date(); 
        exp.setTime(exp.getTime() + Days*24*60*60*1000); 
        document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString+';path=/';
    },
    getCookie:function(name){
        //读cookies
        var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
        if(arr=document.cookie.match(reg)){
            return unescape(arr[2]); 
        }else{
            return null; 
        }
    },
    delCookie:function(name){
        //删除cookies
        var exp = new Date(); 
        exp.setTime(exp.getTime() - 1); 
        var cval=getCookie(name); 
        if(cval!=null){
          document.cookie= name + "="+cval+";expires="+exp.toGMTString()+';path=/'; 
        } 
    }

}
/*
    1 允许登录网格化系统     
    2 允许登录网格化后台管理系统  
    3 允许登录手持终端App  
    4 允许在网格化系统中查看网格实况 
    5 允许在网格化系统中操作作业安全控制
    6 允许在网格化系统工作台中查看设备报修
    7 允许在网格化系统工作台中设备报修里撤销任务
    8 允许在网格化系统工作台中设备报修里转发任务
    9 允许在网格化系统工作台中查看信息上报
    10 允许在网格化系统工作台中查看应急处置以及下发应急处置
    11 允许在网格化系统中查看数据中心
    12 允许员工在手持端上查看作业任务
    13 允许员工在手持端上查看四小时计划
    14 允许员工在手持端上发起语音对讲
    15 允许员工在手持端上发起视频会议
    16 允许员工在手持端上查看设备任务
    17 允许员工在手持端上查看设备维修
    18 允许员工在手持端上查看设备验收
    19 允许员工在手持端上发起点对点视频 
*/
//权限控制
var powers={
    login_front:false,//1 允许登录网格化系统
    login_back:false,//2 允许登录网格化后台管理系统
    see_live_grid:false,//4 允许在网格化系统中查看网格实况
    operate_work_safe:false,//5 允许在网格化系统中操作作业安全控制
    see_device_report:false,//6 允许在网格化系统工作台中查看设备报修
    revoke_device_report:false,//7 允许在网格化系统工作台中设备报修里撤销任务
    repeat_device_report:false,//8 允许在网格化系统工作台中设备报修里转发任务
    see_information_report:false,//9 允许在网格化系统工作台中查看信息上报
    see_emergency:false,//10 允许在网格化系统工作台中查看应急处置以及下发应急处置
    see_count:false,//11 允许在网格化系统中查看数据中心
}
function initPower(){
    var _islocal = storageControl.storagable()
    if(_islocal){
        var _power = sessionStorage.getItem('power') && sessionStorage.getItem('power').split(',')  || ['1']
        for(var i=0;i<_power.length;i++){
          switch(_power[i]){
            case '1':case 1:
              //1 允许登录网格化系统    
              powers.login_front = true
            break;
            case '2':case 2:
              //2 允许登录网格化后台管理系统  
              powers.login_back = true
            break;
            case '4':case 4:
              //4 允许在网格化系统中查看网格实况
              powers.see_live_grid = true
            break;
            case '5':case 5:
              //5 允许在网格化系统中操作作业安全控制
              powers.operate_work_safe = true
            break;
            case '6':case 6:
              //6 允许在网格化系统工作台中查看设备报修
              powers.see_device_report = true
            break;
            case '7':case 7:
              //7 允许在网格化系统工作台中设备报修里撤销任务
              powers.revoke_device_report = true
            break;
            case '8':case 8:
              //8 允许在网格化系统工作台中设备报修里转发任务
              powers.repeat_device_report = true
            break;
            case '9':case 9:
              //9 允许在网格化系统工作台中查看信息上报
              powers.see_information_report = true
            break;
            case '10':case 10:
              //10 允许在网格化系统工作台中查看应急处置以及下发应急处置
              powers.see_emergency = true
            break;
            case '11':case 11:
              //11 允许在网格化系统中查看数据中心
              powers.see_count = true
            break;
          }
        }
    }
}
initPower()

//loading
$.fn.loading = function(type,txt){
    var _this = this
    var _txt = txt?txt:'提交中，请稍候'
    var _loader = `<div class="loader-container text-center color-white">
        <div><i class="fa fa-spinner fa-pulse fa-3x"></i></div>
                <div>${_txt}</div>
        </div>`
    if(type == 'open'){
        _this.addClass('loader')
        _this.append($(_loader))
    }else if(type == 'close'){
        _this.removeClass('loader')
        $('.loader-container').remove()
        // $('.loader').removeClass('loader')
    }      
}
$(function(){
    $('body').loading('open','加载中')
})
$('body').loading('open','加载中')
storageControl.isloginedS()
var navData = {
    accNav1:'organization',
    accNav2:'organization-base',
    accNav3:'0',
    nav1:[
        {id:'0',name:'组织管理',type:'organization',fa:'fa-users',show:true},
        {id:'1',name:'设备管理',type:'device',fa:'fa-wrench',show:true},
        {id:'2',name:'量化任务',type:'quantitave',fa:'fa-trophy',show:true},
        {id:'3',name:'信息管理',type:'info',fa:'fa-comment',show:true},
        {id:'4',name:'作业管理',type:'task',fa:'fa-road',show:true},
        {id:'5',name:'应急处置',type:'emergency',fa:'fa-bolt',show:true}
    ],
    nav2:[
        {sid:'0',id:'0-0',url:'./organization-base-depsetting.html',name:'基础信息',type:'organization',show:true},
        {sid:'1',id:'0-1',url:'./organization-people-base.html',name:'人员信息管理',type:'organization',show:true},
        {sid:'2',id:'0-2',url:'./organization-grid-manage.html',name:'网格管理',type:'organization',show:true},
        {sid:'3',id:'1-0',url:'./device-base.html',name:'设备信息',type:'device',show:true},
        {sid:'4',id:'2-0',url:'./quantitave-manage.html',name:'任务管理',type:'quantitave',show:true},
        {sid:'5',id:'3-0',url:'./info-manage.html',name:'信息分类',type:'info',show:true},
        {sid:'6',id:'4-0',url:'./task-flow.html',name:'作业流程管理',type:'task',show:true},
        {sid:'7',id:'4-1',url:'./task-base.html',name:'作业任务管理',type:'task',show:true},
        {sid:'8',id:'4-2',url:'./task-train-info.html',name:'列车信息管理',type:'task',show:true},
        {sid:'9',id:'5-0',url:'./emergency-base.html',name:'应急处置管理',type:'emergency',show:true}
    ],
    nav3:[
        {id:'0',url:'./organization-base-depsetting.html',name:'部门设置','type':'organization-base',show:true},
        {id:'1',url:'./organization-base-role.html',name:'角色设置','type':'organization-base',show:true},
        {id:'2',url:'./organization-base-station.html',name:'岗位设置','type':'organization-base',show:true},
        {id:'3',url:'./organization-base-info.html',name:'组织信息','type':'organization-base',show:true},
        {id:'4',url:'./organization-people-base.html',name:'人员信息管理','type':'organization-people',show:true},
        {id:'5',url:'./organization-grid-manage.html',name:'网格管理','type':'organization-grid',show:true},
        {id:'6',url:'./device-base.html',name:'设备信息','type':'device',show:true},
        {id:'7',url:'./device-type.html',name:'设备类型','type':'device',show:true},
        {id:'8',url:'./quantitave-manage.html',name:'任务管理','type':'quantitave',show:true},
        {id:'9',url:'./info-manage.html',name:'信息上报','type':'info',show:true},
        {id:'10',url:'./task-flow.html',name:'作业流程管理','type':'task-flow',show:true},
        {id:'11',url:'./task-base.html',name:'作业任务管理','type':'task-base',show:true},
        {id:'12',url:'./task-train-info.html',name:'列车信息管理','type':'task-train',show:true},
        {id:'13',url:'./task-train-station.html',name:'站名管理','type':'task-train',show:true},
        {id:'14',url:'./emergency-base.html',name:'应急处置管理','type':'emergency',show:true}
    ]
}
console.log(powers)
/*
    var powers={
        login_front:false,//1 允许登录网格化系统
        login_back:false,//2 允许登录网格化后台管理系统
        see_live_grid:false,//4 允许在网格化系统中查看网格实况
        operate_work_safe:false,//5 允许在网格化系统中操作作业安全控制
        see_device_report:false,//6 允许在网格化系统工作台中查看设备报修
        revoke_device_report:false,//7 允许在网格化系统工作台中设备报修里撤销任务
        repeat_device_report:false,//8 允许在网格化系统工作台中设备报修里转发任务
        see_information_report:false,//9 允许在网格化系统工作台中查看信息上报
        see_emergency:false,//10 允许在网格化系统工作台中查看应急处置以及下发应急处置
        see_count:false,//11 允许在网格化系统中查看数据中心
    }
*/
if(!powers.login_back && !/login/.test(window.location.pathname)){
    $('body').loading('open','加载中')
    if(sessionStorage.getItem('user_id')){
        alert('该帐号没有后台管理权限，请更换帐号登录')
    }else{
        alert('未登录，请先登录！')
    }
    window.location.href='./login.html';
}

